package com.hyt.it.ogt.controller.pj;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.controller.base.BaseController;
import com.hyt.it.ogt.pj.common.Constants;
import com.hyt.it.ogt.pj.common.ResponseCode;
import com.hyt.it.ogt.pj.model.entity.PieceScore;
import com.hyt.it.ogt.pj.model.vo.CommentRecordVo;
import com.hyt.it.ogt.pj.service.IPieceScoreService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;

/**
 * <p>
 * 评卷块分数表 前端控制器
 * </p>
 *
 * @author qiaozj
 * @since 2020-07-09
 */
@ApiSort(value = 16)
@Api(tags = "16.评卷块分数接口", value = "评卷块分数接口")
@RestController
@RequestMapping("/piece-score")
public class PieceScoreController extends BaseController {

    @Autowired
    private IPieceScoreService pieceScoreService;

    @ApiOperationSort(value = 1)
    @ApiOperation(value = "16.1.1根据id获取评卷块分数", notes = Constants.SWAGGER_METHOD_NOTES)
    @GetMapping("query/{id}")
    public Object query(@PathVariable("id") String id){
        PieceScore pieceScore = pieceScoreService.getById(id);
        if(pieceScore != null){
            return ApiResponse.builder().code(ResponseCode.SUCCESS).data(pieceScore).build();
        }else{
            return ApiResponse.builder().code(ResponseCode.ERROR).build();
        }
    }

    @ApiOperationSort(value = 10)
    @ApiOperation(value = "16.2.1添加评卷块分数", notes= Constants.SWAGGER_METHOD_NOTES)
    @GetMapping("add")
    public Object add(@RequestBody PieceScore pieceScore){
        Boolean flag = pieceScoreService.save(pieceScore);
        if(flag){
            return ApiResponse.builder().code(ResponseCode.SUCCESS).build();
        }else{
            return ApiResponse.builder().code(ResponseCode.ERROR).build();
        }
    }

    @ApiOperationSort(value = 20)
    @ApiOperation(value = "16.3.1更新评卷块分数", notes = Constants.SWAGGER_METHOD_NOTES)
    @PutMapping("update")
    public Object update(@RequestBody PieceScore pieceScore){
        boolean flag = pieceScoreService.updateById(pieceScore);
        if(flag){
            return ApiResponse.builder().code(ResponseCode.SUCCESS).build();
        }else{
            return ApiResponse.builder().code(ResponseCode.ERROR).build();
        }
    }

    @ApiOperationSort(value = 30)
    @ApiOperation(value = "16.4.1根据id删除评卷块分数", notes = Constants.SWAGGER_METHOD_NOTES)
    @DeleteMapping("delete/{id}")
    public Object delete(@PathVariable("id") String id){
        boolean flag = pieceScoreService.removeById(id);
        if(flag){
            return ApiResponse.builder().code(ResponseCode.SUCCESS).build();
        }else{
            return ApiResponse.builder().code(ResponseCode.ERROR).build();
        }
    }

    @ApiOperationSort(value = 5)
    @ApiOperation(value = "16.5.1根据准考证号获取评卷块分数", response = CommentRecordVo.class,notes = Constants.SWAGGER_METHOD_NOTES)
    @GetMapping("queryByEncodeId/{projectId}/{subjectId}/{encodeId}")
    public Object queryByEncodeId(@PathVariable("projectId") String projectId,@PathVariable("subjectId") String subjectId,@PathVariable("encodeId") String encodeId){
        try {
            CommentRecordVo  commentRecordVo = pieceScoreService.selectCommentRecordVo(projectId,subjectId,encodeId);
            return ApiResponse.builder().code(ResponseCode.SUCCESS).data(commentRecordVo).build();
        }catch (Exception e){
            logger.error("PieceScoreControllerl接口queryByEncodeId方法异常:{}",e);
            return ApiResponse.builder().code(ResponseCode.ERROR).build();
        }


    }


}
